import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    children: [
      {
        path: '/about/:type', // :id就是要给路由配置的动态数据  id会成为params参数中的key 
        name: 'About',
        component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
      },
      {
        path: 'page',
        name: "Page1",
        component: () => import('../views/page1.vue')
      },
      {
        path: 'page/page2',
        name: "Page2",
        component: () => import('../views/page2.vue')
      },
      {
        path: 'page/page2/page3',
        name: "Page3",
        component: () => import('../views/page3.vue')
      },
      {
        path: 'page/page2/page3/page4',
        name: "Page4",
        component: () => import('../views/page4.vue')
      }
    ]
  }
]

const router = new VueRouter({
  routes
})
const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  // console.log(location)
  if(typeof(location)=="string"){
    var Separator = "&";
    if(location.indexOf('?')==-1) { Separator='?'; }
    location = location + Separator + "random=" + Math.random();
  }
  return routerPush.call(this, location).catch(error=> error)
}
export default router
